package game;

import java.awt.*;

public class Player {
    private int x, y, width, height;

    public Player(int x, int y, int width, int height) {
        this.x = x; this.y = y;
        this.width = width; this.height = height;
    }

    public void move(int dx, int dy) {
        x += dx;
        x = Math.max(0, Math.min(x, 500 - width)); // 不出边界
    }

    public void draw(Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        // 玩家绘成一个蓝色箭头状飞船
        int[] xPoints = {x, x + width / 2, x + width};
        int[] yPoints = {y + height, y, y + height};
        g2d.setColor(new Color(0, 255, 255));
        g2d.fillPolygon(xPoints, yPoints, 3);
    }


    public Rectangle getBounds() {
        return new Rectangle(x, y, width, height);
    }
}
